<template name="audithome">
  <view class="audithome">
    <view class="navigation">
      <view class="navigationMain">
        <!-- <image class="navigationIcon" src="../../static/arrow1.png" mode="" @click="navigateBack"></image> -->
        <view class="launchapp" @click="navigateBack">
          <image src="../../static/arrow1.png" mode=""></image>
        </view>
        <text class="navigationText">Loan details</text>
      </view>
      <image class="banner" src="/static/banner/banner5.jpg" mode="aspectFill" />
    </view>
    <view class="main">
      <view class="title">Current Loan</view>
      <view class="amount">{{ infoData.amount }}</view>
      <view class="subtitle">Loan amount</view>
      <view class="item1">
        <view class="label">{{ infoData.field1 }}</view>
        <view class="value">{{ infoData.date }}</view>
      </view>
      <view class="item2">
        <view class="label">Loan number</view>
        <view class="value">application time</view>
      </view>
      <view class="submit"> LOAN REVIEW </view>
      <view class="bsubtitle" @click="popupOpen">{{ infoData.title }}</view>
    </view>
    <uni-popup ref="popup" type="center" class="popupRef">
      <view class="popup">
        <view class="popupTitle">Tips</view>
        <view class="popupMain">
          <view class="popupText">• 22-50 years old</view>
          <view class="popupText">• Have a stable income and the ability to repay debts</view>
        </view>
        <view class="popupBtn" @click="popupClose">GOT&nbsp;&nbsp;&nbsp;IT</view>
      </view>
    </uni-popup>
    <view class="cu-bar tabbar bg-white shadow foot" style="height: 182rpx">
      <view :class="PageCur == 'home' ? 'action text-red' : 'action text-gray'" @click="NavChange" data-cur="home">
        <view class="cuIcon-homefill"></view>Home
      </view>
      <view :class="PageCur == 'mine' ? 'action text-red' : 'action text-gray'" @click="NavChange" data-cur="mine">
        <view class="cuIcon-peoplelist"></view>Me
      </view>
    </view>
  </view>
</template>

<script>
import dayjs from 'dayjs';
import $_storage from '../../common/util/storage'
import { getDecryptString } from '../../defaut';
import CryptoJS from "crypto-js";
export default {
  name: 'audithome',
  data() {
    const authentication4 = $_storage.getStorage('authentication_4');
    // 获取当天日期
    const data = dayjs(new Date()).format('YYYY-MM-DD');
    // 获取唯一串码
     // const stringcode = $_storage.getStorage('stringcode')
    return {
      PageCur: 'home',
      infoData: {
        amount: '', //authentication4 ? authentication4.loanable_amount : 0
        field1: '',
        date: data,
        title: 'Borrowing Conditions',
      },
    };
  },
  onShow() {
	  uni.setStorageSync('currentPage', '/pages/audit/audithome'); // 保存当前页面到本地存储
	  this.hashString()
	  this.usermessage()
  },
  methods: {
	  // 获取 额度
	  // 用户信息获取 客服
	  usermessage(){
	  	this.$http.get("/user/v1/getcurruser", {}).then(res => {
	  		if (res.data.status == 200) {
	  			let arr = JSON.parse(getDecryptString(res.data.data, this.$password()));
	  			  this.infoData.amount= arr.loanAmount;
	  		}
	  	})
	  },
	  // 处理唯一字符
	hashString:function() {
		 // let arr=CryptoJS.MD5(uni.getStorageSync("phone").toString())
		 // arr=arr.substring(0,10)
		 // this.infoData.field1 = BigInt("0x" + arr).toString() 
		 const phone = uni.getStorageSync("phone").toString();
		 const hash = CryptoJS.MD5(phone).toString();
		 const truncatedHash = hash.substring(0, 12);
		 this.infoData.field1 = BigInt("0x" + truncatedHash).toString();
	},
    // 打开弹框
    popupOpen: function () {
      this.$refs.popup.open()
    },
    // 关闭弹框
    popupClose: function () {
      this.$refs.popup.close()
    },
    NavChange: function (e) {
      this.PageCur = e.currentTarget.dataset.cur;
      const pages = getCurrentPages();
      const currentPage = pages[pages.length - 1];
      const routes = {
        "pages/audit/auditmine": 'mine',
        "pages/audit/audithome": 'home',
      }
      if (routes[currentPage.route] == this.PageCur) return

      if (e.currentTarget.dataset.cur == "mine") {
        this.$Router.replaceAll({
          name: "auditmine",
        });
      } else if (e.currentTarget.dataset.cur == "home")
        this.$Router.replaceAll({
          name: "audithome",
        });
    },
    // 返回
    navigateBack() {
      // #ifdef H5
      // uni.removeStorageSync("token");
      // uni.navigateTo({
      //   url: "/pages/login/login",
      // });
      // uni.removeStorageSync("token");
      // this.$Router.replace({ name: 'login' })
      // #endif

      // #ifdef APP-PLUS
      uni.removeStorageSync("token");
      if (plus.os.name.toLowerCase() === "android") {
        plus.runtime.quit();
      } else {
        const threadClass = plus.ios.importClass("NSThread"); // 导入了iOS的 NSThread 类。
        const mainThread = plus.ios.invoke(threadClass, "mainThread"); // 通过调用 NSThread 类的 mainThread 方法获取主线程对象。
        plus.ios.invoke(mainThread, "exit"); //调用主线程对象的 exit 方法，退出应用程序。
        // ios11
        plus.ios
          .import("UIApplication")
          .sharedApplication()
          .performSelector("exit"); //导入 UIApplication 类，调用 sharedApplication 方法获取应用程序对象，然后使用 performSelector 方法调用应用程序对象的 exit 方法,  针对iOS 11及以上版本的退出方式
      }
      //   #endif

      // uni.exit({
      //   success: function () {
      //     console.log("应用程序成功退出");
      //   },
      //   fail: function (err) {
      //     console.log("退出应用程序失败:", err);
      //   },
      // });
    },
  },
};
</script>

<style scoped>
page {
  /* min-height: 100vh; */
  padding-bottom: 24rpx;
  box-sizing: border-box;
}



.navigation {
  background: rgba(82, 118, 238);
  display: flex;
  align-items: center;
  text-align: center;
  flex-direction: column;
  padding: 80rpx 26rpx 20rpx;
  position: relative;

}

.navigation .navigationMain {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 1000;
  width: 100%;
  display: flex;
  align-items: center;
  padding: 20rpx 24rpx;
}

.navigation .navigationMain .navigationIcon {
  width: 32rpx;
  height: 38rpx;
}

.navigation .navigationMain .navigationText {
  width: 100%;
  font-size: 38rpx;
  font-weight: 400;
  color: #fff;
  line-height: 54rpx;
  letter-spacing: 2rpx;
}

.navigation .banner {
  width: 100%;
  height: 350rpx;
}

.launchapp {
  width: 32rpx;
  height: 38rpx;
  border: none;
  background: none;
  box-shadow: none;
  background-color: none;
  padding-left: 0;
  padding-right: 0;
  margin-left: 0;
  margin-right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.launchapp image {
  width: 100%;
  height: 100%;
}

.audithome {
  min-height: 100vh;
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  /* background: rgba(245, 245, 245, 1); */
  position: relative;


}

.audithome .popupRef {
  display: flex;
  justify-content: center;
  align-items: center;
}

.audithome .popup {
  background: #fff;
  padding: 36rpx 42rpx;
  margin: 0 48rpx;
  border-radius: 8rpx;
  box-sizing: border-box;


}

.audithome .popup .popupTitle {
  font-weight: bold;
  color: #000;
  font-size: 36rpx;
}

.audithome .popup .popupMain {
  margin-top: 40rpx;
  padding: 0rpx 12rpx;


}

.audithome .popup .popupMain .popupText {
  font-size: 32rpx;
  color: #000;
  font-family: revert;
  font-weight: 400;
}

.audithome .popup .popupBtn {
  margin-top: 20rpx;
  display: flex;
  justify-content: flex-end;
  font-size: 24rpx;
  font-weight: bold;
  line-height: 40rpx;
  /* white-space: 0; */
  letter-spacing: -2rpx;

  color: rgba(25, 144, 132);
}

.audithome .main {
  position: absolute;
  top: 270rpx;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 48rpx);
  background: #fff;
  border-radius: 16rpx;
  padding: 36rpx 24rpx 24rpx 24rpx;
  display: flex;
  flex-direction: column;
  align-items: center;

}

.audithome .main .title {
  font-weight: bold;
  font-size: 38rpx;
  color: #000;
}

.audithome .main .amount {
  margin-top: 20rpx;
  font-weight: 400;
  font-size: 56rpx;
  color: rgba(170, 170, 170, 1);
}

.audithome .main .subtitle {
  margin-top: 0rpx;
  font-size: 32rpx;
  color: #999;
  font-weight: 400;
}

.audithome .main .item1 {
  margin-top: 60rpx;
  width: 100%;
  color: #333;
  font-size: 32rpx;
  font-weight: 400;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.audithome .main .item2 {
  margin-top: 14rpx;
  width: 100%;
  color: #999;
  font-size: 32rpx;
  font-weight: 400;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.audithome .main .submit {
  margin-top: 40rpx;
  width: 100%;
  padding: 24rpx 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 32rpx;
  /* font-weight: bold; */
  border-radius: 48rpx;
  background: rgba(255, 187, 50, 1);
}

.audithome .main .bsubtitle {
  margin-top: 24rpx;
  text-decoration: underline;
  color: #999;
  font-size: 28rpx;
}

/* 头部额度部分 */
</style>